<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Init extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()//,'default'=>password_hash('cyunjuk888')
    {
        $users = $this->table('user', array('engine' => 'MyISAM'));
        $users->addColumn('username', 'string', array('limit' => 16, 'comment' => '用户名'))
            ->addColumn('password', 'string', array('limit' => 129, 'comment' => '用户密码'))
            ->addColumn('group_id', 'integer', array('null' => true, 'comment' => '组id'))
            ->addColumn('rights', 'integer', array('default' => 2, 'comment' => '权限'))
            ->addColumn('created', 'datetime', array('null' => true))
            ->addIndex(array('username'), array('unique' => true))
            ->create();

        $group = $this->table('group', array('engine' => 'MyISAM'));
        $group->addColumn('name', 'string', array('limit' => 16,'comment' => '组名'))
            ->addColumn('remarks', 'string', array('limit' => 128, 'null' => true, 'comment' => '备注'))
            ->addColumn('selected', 'boolean', array('default' => false))
            ->addColumn('created', 'datetime', array('null' => true))
            ->addIndex(array('name'), array('unique' => true))
            ->create();

        $account = $this->table('wechat_account', array('engine' => 'MyISAM'));
        $account->addColumn('group_id', 'integer', array('null' => true, 'comment' => '组id'))
            ->addColumn('name', 'string', array('limit' => 16, 'comment' => '账号名'))
            ->addColumn('wechat_id', 'string', array('limit' => 64, 'comment' => '微信号'))
            ->addColumn('qr_img', 'string', array('limit' => 128, 'default' => '', 'comment' => '二维码图'))
            ->addColumn('fans', 'integer', array('default' => 0, 'comment' => '粉丝数'))
            ->addColumn('status', 'enum', array('values'=>array('1', '2', '3'), 'default'=>'1', 'comment'=>'状态,1:吸粉,2:暂停,3:封号'))
            ->addColumn('remarks', 'string', array('limit' => 128, 'null' => true, 'comment' => '备注'))
            ->addColumn('created', 'datetime', array('null' => true))
            ->create();
    }
}
